#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H

#include <QObject>
#include <QString>
#include <QSettings>

class ConfigManager : public QObject
{
    Q_OBJECT

public:
    explicit ConfigManager(QObject *parent = nullptr);
    ~ConfigManager();

    // Getter methods
    int checkInterval() const;
    int highFreqThreshold() const;
    int lowFreqThreshold() const;
    int sustainedPeriodHigh() const;
    int sustainedPeriodLow() const;
    int freqReduction() const;
    int freqIncrease() const;
    int targetFreqAfterReduction() const;
    int ioCriticalThreshold() const;
    int ioSevereThreshold() const;
    int ioHighThreshold() const;
    QString logFile() const;
    int maxLogSizeMB() const;
    int maxLogFiles() const;

    // Setter methods
    void setCheckInterval(int value);
    void setHighFreqThreshold(int value);
    void setLowFreqThreshold(int value);
    void setSustainedPeriodHigh(int value);
    void setSustainedPeriodLow(int value);
    void setFreqReduction(int value);
    void setFreqIncrease(int value);
    void setTargetFreqAfterReduction(int value);
    void setIoCriticalThreshold(int value);
    void setIoSevereThreshold(int value);
    void setIoHighThreshold(int value);
    void setLogFile(const QString &value);
    void setMaxLogSizeMB(int value);
    void setMaxLogFiles(int value);

    // Service control methods
    bool isServiceRunning() const;
    bool startService();
    bool stopService();
    bool restartService();
    QString serviceStatus() const;

    // Save and load methods
    void saveConfig();
    void loadConfig();

signals:
    void configChanged();

private:
    void initDefaultValues();

    // Configuration values
    int m_checkInterval;
    int m_highFreqThreshold;
    int m_lowFreqThreshold;
    int m_sustainedPeriodHigh;
    int m_sustainedPeriodLow;
    int m_freqReduction;
    int m_freqIncrease;
    int m_targetFreqAfterReduction;
    int m_ioCriticalThreshold;
    int m_ioSevereThreshold;
    int m_ioHighThreshold;
    QString m_logFile;
    int m_maxLogSizeMB;
    int m_maxLogFiles;

    QSettings *m_settings;
};

#endif // CONFIGMANAGER_H